<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<link rel="stylesheet" type="text/css" href="../css/index.css" />
		<script src="../js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/vant.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			document.addEventListener('plusready', function() {
				//console.log("所有plus api都应该在此事件发生后调用，否则会出现plus is undefined。"
			});
		</script>
		<title></title>

	</head>

	<body>
		<div id="app">
			<van-row>
				<van-nav-bar title="注册账号" left-text="返回" right-text="确认" left-arrow id="one" @click-left="back"></van-nav-bar>

			</van-row>

			<van-row id="two">
				<van-cell-group>
					<van-field v-model="phone" label="手机号" placeholder="请输入手机号" id="z1"></van-field>

					<van-field v-model="sms" center clearable label="短信验证码" placeholder="请输入短信验证码" id="z2">
						<van-button slot="button" size="small" type="primary" @click="yzm">发送验证码</van-button>
					</van-field>
				</van-cell-group>
				<!--密码-->
				<van-cell-group>

					<van-field v-model="password" type="password" placeholder="设置登录密码（至少6位）" id="z3"></van-field>
					<van-field v-model="rpassword" type="password" size="" placeholder="请确密码" id="z4"></van-field>
					<van-field v-model="name" placeholder="昵称（最多20字）" id="z5"></van-field>
					<van-field v-model="code" placeholder="县/区Code" id="z6"></van-field>
				</van-cell-group>
			</van-row>
			<p>注册会员及表示同意<a href="#">《协议》</a></p>
			<van-col span="24" id="dl">
				<van-button size="large" square type="danger" @click="zcdl">立即注册</van-button>
			</van-col>
		</div>
		<script type="text/javascript">
			var _this = this;
			var yzm = ""
			var app = new Vue({
				el: "#app",
				data: {
					chosenAddressId: "",
					password: "",
					list: [],
					sms: yzm,
					rpassword: "",
					name: "",
					code: "",
					phone: ""
				},
				methods: {
					back: function() {
						//window.location.href="login.html"
						plus.webview.open("login.html", "lo");
					},
					zcdl: function() {
						var _this = this;
						if (_this.password != _this.rpassword) {
							app.$toast("密码错误或者不一致");
						} else {
							ajax({
								url: "http://dsapi.ysd3g.com/API/UserRegister",
								dataType: "JSONP",
								data: {
									phone: _this.phone,
									code: yzm,
									password: _this.password,
									districtCode: 410522,
									nickName: _this.name
								},
								success: function(res) {
									var _this = this;
									console.log()
									if (_this.password == _this.rpassword) {
										app.$toast("用户：" + res.UserData.NickName + "注册成功");
										//window.location.href="login.html"
										plus.webview.open("login.html", "lo");
									} else {
										app.$toast("注册失败");
									}
								}

							});
						}
					},
					yzm: function() {
						var _this = this;
						ajax({
							url: "http://dsapi.ysd3g.com/API/SendRegisterPhoneCode",
							dataType: "JSONP",
							data: {
								phone: _this.phone,
							},
							success: function(res) {
								console.log(res)
								if (res.Error) {
									app.$toast("手机号码不正确哦！");
								} else {
									app.$toast(res.Code);
								}
								yzm = res.Code
								console.log(yzm)
							}
						});
					}
				}
			});
		</script>
	</body>

</html>
